import json
import time
from .config import Config
from .rabbitmq_client import RabbitMQProducer

def send_msg_to_mq(param={}):
    """生产者示例"""
    # 创建生产者实例
    producer = RabbitMQProducer(Config.as_dict())
    
    try:
        # 创建任务消息
        task_message = param
        print(task_message)

        # 发送消息
        success = producer.publish(
            exchange='direct_exchange',
            routing_key='task',
            message=json.dumps(task_message),
            properties={
                'priority': min(1, 10)  # 设置消息优先级
            }
        )

        if success:
            print(f"消息发送成功")
        else:
            print(f"消息发送失败")
    finally:
        # 关闭连接
        producer.close()

if __name__ == "__main__":
    param={
        "key":"orsdsdad",
        "v":"aakkkc"
    }
    send_msg_to_mq(param)